<div id="main-content">
  <div class="container-fluid">
    <div class="row-fluid">
      <div class="span12">
        <div class="widget-block">
          <?php
          if($message == 'filed'){
          ?>
          <div class="alert alert-error fade in">
            <button data-dismiss="alert" class="close" type="button">×</button>
            <strong>Filed!</strong> Fail to save data.
          </div>
          <?php
          }
          if($message == 'sukses'){
          ?>
          <div class="alert alert-success fade in">
            <button data-dismiss="alert" class="close" type="button">×</button>
            <strong>Success!</strong> Now you have new user.
          </div>
          <?php
          }
          ?>
          <div class="widget-head">
            <h5><?php print $title_table?></h5>
            <div class="widget-control pull-right">
              <a href="#" data-toggle="dropdown" class="btn dropdown-toggle"><i class="icon-cog"></i><b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li><a href="<?php print  site_url("outlet/tambahan/export-xls-target/".$outlet[0]->id_outlet."/".$year) ?>"><i class="black-icons excel_document"></i> Export to XLS</a></li>
                <li><a href="<?php print  site_url("outlet/tambahan/import-xls-target/".$outlet[0]->id_outlet."/".$year) ?>"><i class="black-icons excel_document"></i> Import XLS</a></li>
              </ul>
            </div>
          </div>
          <div class="widget-content">
            <div class="widget-searchbox">
              <?php print $this->form_eksternal->form_open()?>
              <ul>
                <li class="row-counts">
                  <div class="input-prepend"> <span class="add-on">Tahun</span>
                    <?php 
                    $th = date("Y");
                    $kecil = $th - 4;
                    $besar = $th + 4;
                    for($bv = $th ; $bv > $kecil ; $bv--){
                      $jadi[$bv] = $bv;
                    }
//                    $jadi[] = $th;
                    for($bv = ($th + 1) ; $bv < $besar ; $bv++){
                      $jadi[$bv] = $bv;
                    }
                    asort($jadi);
                    print $this->form_eksternal->form_dropdown("tahun", $jadi, array($year), "id='settahun'");?>
                  </div>
                </li>
              </ul>
            </div>
            <div class="widget-box">
              <?php print $this->form_eksternal->form_open("","",array("id_outlet" => $outlet[0]->id_outlet))?>
              <table class="data-tbl-box table">
                <thead>
                  <tr>
                    <th>Bulan</th>
                    <th>Service</th>
                    <th>Service + Belanja</th>
                    <th>Belanja</th>
                    <th>Rata-rata Rupiah Service</th>
                    <th>Rata-rata Rupiah Belanja</th>
                    <th>% HPP</th>
                  </tr>
                </thead>
                <tbody>
                  <?php
                  $data = array(
                      1 => "Januari",
                      2 => "Februari",
                      3 => "Maret",
                      4 => "April",
                      5 => "Mei",
                      6 => "Juni",
                      7 => "Juli",
                      8 => "Agustus",
                      9 => "September",
                      10 => "Oktober",
                      11 => "Nopember",
                      12 => "Desember",
                  );
                  if($this->nbscache->get_olahan("permission", $this->session->userdata("id_privilege"), "edit_target_tahunan", "edit") == TRUE ){
                    $disab = "";
                    $footd = '<tfoot>
                  <tr>
                    <td colspan="7"><button class="btn btn-primary" type="submit">Save changes</button></td>
                  </tr>
                </tfoot>';
                  }
                  else{
                    $disab = "";
                    $footd = '<tfoot>
                  <tr>
                    <td colspan="7"><button class="btn btn-primary" type="submit">Save changes</button></td>
                  </tr>
                </tfoot>';
                  }
                  if(is_array($data_target)){
                    foreach ($data_target as $key => $value) {
                      print "
                  <tr>
                    <td>{$data[$value->month]}</td>
                    <td>".$this->form_eksternal->form_input("service[{$key}]", $value->service, 'style="width: 90%" '.$disab)."</td>
                    <td>".$this->form_eksternal->form_input("service_belanja[{$key}]", $value->service_belanja, 'style="width: 90%" '.$disab)."</td>
                    <td>".$this->form_eksternal->form_input("belanja[{$key}]", $value->belanja, 'style="width: 90%" '.$disab)."</td>
                    <td>".$this->form_eksternal->form_input("rp_service[{$key}]", $value->rata_service, 'style="width: 90%" '.$disab)."</td>
                    <td>".$this->form_eksternal->form_input("rp_belanja[{$key}]", $value->rata_belanja, 'style="width: 90%" '.$disab)."</td>
                    <td>".$this->form_eksternal->form_input("hpp[{$key}]", $value->hpp, 'style="width: 90%" '.$disab)."</td>
                  </tr>";
                    }
                  }
                  ?>
                </tbody>
                <?php print $footd?>
              </table>
              </form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<script>
  $(document).ready( function () {
    $("#settahun").change(function(){
      window.location = "<?php print site_url("outlet/tambahan/add-target/".$outlet[0]->id_outlet."/")?>/" + $("#settahun").val();
    });
  });
</script>